using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using OpenComposite.EII.Repository;
using System.Drawing;
using OpenComposite.Base.Designer;

namespace OpenComposite.EII.Designer.BusinessProcess
{
	public class BusinessProcessDesignController : DesignController
	{
		#region Initialization
		public BusinessProcessDesignController(RepositorySurfaceManager surfaceManager)
			: base(surfaceManager)
		{
			init();
		}
		private void init()
		{
			this.contextMain = new System.Windows.Forms.ContextMenuStrip();

			// 
			// contextMain
			// 
			this.contextMain.Items.Add("Generate Code...", null, new EventHandler(this.context_GenerateCode));
		}
		#endregion

		#region Public Members

		#region Properties
		// override
		public override ContextMenuStrip AdditionalContextMenuStrip
		{
			get
			{
				return contextMain;
			}
		}
		#endregion

		#endregion

		#region Protected Members

		#region Methods
		// overrided
		protected override void LoadDiagram()
		{
			RepositoryService repSvc = (RepositoryService)this.GetService(typeof(RepositoryService));
			if ( repSvc == null )
				throw new NullReferenceException("RepositoryService not available.");

			//DesignerControl dc = null;
			if ( this.DiagramItem == null )
				throw new NullReferenceException("_diagramItem == null.");

			if ( this.DiagramItem.Diagram == null ) {
				// create start and end symbols
				StartSymbol start = repSvc.CreateDesignerControl(ItemType.BProcess_Start, false) as StartSymbol;
				EndSymbol end = repSvc.CreateDesignerControl(ItemType.BProcess_End, false) as EndSymbol;
				start.Location = new Point(2250, 2500);
				end.Location = new Point(2750, 2500);
				this.DesignerDockContent.DesignerView.AddDesignerControl(start);
				this.DesignerDockContent.DesignerView.AddDesignerControl(end);
			} else {
				// load diagram
				this.DesignerDockContent.DesignerView.BeginUpdate();
				this.DesignerDockContent.DesignerView.LoadDiagramFromXml(this.DiagramItem.Diagram, DesignerControlTypes.ToArray());
				this.DesignerDockContent.DesignerView.EndUpdate();
			}
			LoadItems();
		}
		#endregion

		#endregion

		#region Private Members

		#region Variables
		private System.Windows.Forms.ContextMenuStrip contextMain;
		#endregion

		#region Methods
		private void context_GenerateCode(object sender, EventArgs e)
		{
		}
		#endregion

		#endregion
	}
}
